package com.herui.ota.controller;

import com.herui.ota.config.ControllerNames;
import com.herui.ota.entity.UserAdmin;
import com.herui.ota.pojo.form.UserAdminFilterForm;
import com.herui.ota.pojo.form.UserAdminForm;
import com.herui.ota.service.UserAdminService;
import com.mlnx.common.annotations.NeedLogin;
import com.mlnx.common.entity.Response;
import com.mlnx.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.shan.spring.base.RdBaseController;
import org.shan.spring.base.annotations.SysLog;
import org.shan.spring.mybatis.service.ICurdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * Created by amanda.shan on 2020/5/19.
 */
@Api(value = ControllerNames.AdminName + "接口", tags = {ControllerNames.AdminName + "接口"})
@SysLog(title = ControllerNames.AdminName)
@RestController
@RequestMapping("/admin")
public class AdminController extends RdBaseController<UserAdmin, UserAdminFilterForm> {

    @Autowired
    private UserAdminService service;
    @Override
    public ICurdService getService() {
        return service;
    }
    @Override
    public UserAdmin newInstance(Integer id) {
        UserAdmin o = new UserAdmin();
        o.setId(id);
        return o;
    }

    @NeedLogin
    @SysLog(
            businessType = BusinessType.INSERT
    )
    @ApiOperation(
            value = "新增",
            notes = ""
    )
    @PostMapping({""})
    public Response add(@Valid UserAdminForm form) throws IllegalAccessException, InstantiationException {
        service.save(form);
        return this.result();
    }

    @NeedLogin
    @SysLog(
            businessType = BusinessType.UPDATE
    )
    @ApiOperation(
            value = "更改",
            notes = ""
    )
    @PutMapping({"/{id}"})
    public Response modify(@PathVariable("id") Integer id, @Valid UserAdminForm form) {
        service.update(id, form);
        return this.result();
    }
}
